package io.light.frame.dal.mybatis.generator.core.listener;

import io.light.frame.dal.mybatis.generator.core.context.GenResult;
import io.light.frame.dal.mybatis.generator.core.domain.Generation;
import io.light.frame.dal.mybatis.generator.core.domain.clazz.Clazz;
import io.light.frame.dal.mybatis.generator.core.domain.mapper.Mapper;
import io.light.frame.dal.mybatis.generator.core.domain.mapper.MapperFunc;
import org.springframework.core.Ordered;

/**
 * Generation listener
 *
 * @author Ivan
 * @version 1.0.0
 * @date 2021-06-14 10:57
 * @see io.light.frame.dal.mybatis.generator.core.context.GenerationContext
 */
public interface GenerationListener extends Ordered {

    /**
     * On generation start
     *
     * @param generation {@link Generation}
     */
    default void onStart(Generation generation) {}

    /**
     * On metadata mapped
     *
     * @param mapper {@link Mapper}
     * @see io.light.frame.dal.mybatis.generator.core.meta.entity.Table
     * @see io.light.frame.dal.mybatis.generator.core.meta.entity.TableColumn
     */
    default void onMetadataMapped(Mapper mapper) {}

    /**
     * On entity definition Ready
     *
     * @param entityClazz {@link Clazz}
     */
    default void onEntityReady(Clazz entityClazz) {}

    /**
     * On Mapper function definition Ready
     *
     * @param mapperFunc {@link MapperFunc}
     * @param content {@link MapperFunc.Content}
     */
    default void onMapperFuncReady(MapperFunc mapperFunc, MapperFunc.Content content) {}

    /**
     * On {@link Mapper} definition Ready
     *
     * @param mapper {@link Mapper}
     * @param daoClazz {@link Clazz}
     */
    default void onMapperReady(Mapper mapper, Clazz daoClazz) {}

    /**
     * On generation success
     *
     * @param result {@link GenResult}
     */
    default void onSuccess(GenResult result) {}

    /**
     * On generation error
     *
     * @param error {@link Exception}
     */
    default void onError(Exception error) {}

    /**
     * On generation complete
     *
     * @param result {@link GenResult}
     */
    default void onComplete(GenResult result) {}

    /**
     * Order weight
     *
     * @return {@code int}
     */
    @Override
    default int getOrder() {
        return 0;
    }
}
